package action;
import java.io.File;
import java.io.IOException;

import javax.xml.parsers.*;

import mondel.MondeDao;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class ExpXML {
    private NodeList no;
	public ExpXML() throws ParserConfigurationException, SAXException, IOException
	{
		File f=new File("SelectType.xml");
		DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
		DocumentBuilder builder=factory.newDocumentBuilder();
	    Document doc = builder.parse(f);
	    no = doc.getElementsByTagName("bean");
	}
	public String[] selectAllType()
	{
		 String s[]=new String[no.getLength()];
		 if(no!=null)
		 {
			 for(int i=0;i<no.getLength();i++)
			 {
				 Element element=(Element)no.item(i);
				 s[i]=element.getAttribute("id");
			 }
		 }
		 return s;
		
	}
	public MondeDao selectProperty(String id)
	{
		String mondo="";
		 if(no!=null)
		 {
			 for(int i=0;i<no.getLength();i++)
			 {
				 Element element=(Element)no.item(i);
				 String s=element.getAttribute("id");
				 if(s.equals(id))
				 {					 
					mondo=element.getAttribute("property");
				 }
			 }
		 }
		 MondeDao mon = null;
		 try {
			
			try {
				mon=(MondeDao)Class.forName(mondo).newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
		
			e.printStackTrace();
		}
		return mon;
	}

}
